import { WuXingGradeUpPanel } from "./WuXingGradeUpPanel";
import { WuXingQuickGradeUpAlert } from "./WuXingQuickGradeUpAlert";
import { EventName } from "../../mvc/EventName";
import { DataEvent } from "../../events/DataEvent";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { WuXingQualityBuyPanel } from "./WuXingQualityBuyPanel";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { ItemData } from "../../resource/info/ItemData";
import { PopupManager } from "../../manager/PopupManager";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ObjCreate } from "../common/ObjCreate";
import { Cache } from "../../cache/Cache";
import { EActiveType } from "../../../../Message/Public/EActiveType";
import { EffectManager } from "../../manager/EffectManager";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { TodayNotTipUtil } from "../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../component/gconst/TodayNoTipsConst";
import { Alert } from "../../../../com/mui/controls/Alert";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { WuXingConfig } from "../../resource/WuXingConfig";
import { WuXingRule } from "../../rules/WuXingRule";
import { ExpAddEffect } from "../effect/ExpAddEffect";
import { ExpAddEffectInfo } from "../../resource/info/ExpAddEffectInfo";
import { AttributeTextType } from "../../scene/player/type/AttributeTextType";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class WuXingQualityPanel
    
    export  class WuXingQualityPanel extends WuXingGradeUpPanel
    {
        constructor(arg1: int=428, arg2: int=438)
        {
            super(arg1, arg2);
            return;
        }

        protected get quickOptAlert(): WuXingQuickGradeUpAlert
        {
            if (!this._quickOptAlert) 
            {
                this._quickOptAlert = new WuXingQuickGradeUpAlert();
                this._quickOptAlert.addEventListener(EventName.WuXingQualityAlertOk, this.onQuickOptAlertHandler);
            }
            return this._quickOptAlert;
        }

        protected onQuickOptAlertHandler(arg1: DataEvent): void
        {
            if (this.moneyCheck()) 
            {
                _info.qualityAutoBuy = this._itemBuyPanel.autoBuyCheck;
                Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingQualityAutoReq, _currentItem));
            }
            return;
        }

        protected initItemBuyPanel(): void
        {
            this._itemBuyPanel = new WuXingQualityBuyPanel(ECategory._ECategoryProp, EProp._EPropWuXingSpiritUpgrade);
            this._itemBuyPanel.x = _bg1.x + 20;
            this._itemBuyPanel.y = _line.y + 25;
            addChild(this._itemBuyPanel);
            return;
        }

        protected moneyCheck(): Boolean
        {
            if (this._itemBuyPanel.moneyNeed > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, this._itemBuyPanel.moneyNeed));
                MsgManager.showRollTipsMsg(Language.getString(20038));
                return false;
            }
            return true;
        }

        protected /* override */ optAble(arg1: ItemData): Boolean
        {
            if (super.optAble(arg1)) 
            {
                if (arg1.wxColor >= 5) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(60205));
                    return false;
                }
                if (arg1.wxLevel < 10) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(26403));
                    return false;
                }
                return true;
            }
            return false;
        }

        protected /* override */ onWuXingBgLoadedHandler(): void
        {
            super.onWuXingBgLoadedHandler();
            return;
        }

        protected /* override */ onOptBtn1ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            super.onOptBtn1ClickHandler(arg1);
            if (_currentItem) 
            {
                if (this.optAble(_currentItem)) 
                {
                    if (this.moneyCheck()) 
                    {
                        _info.qualityAutoBuy = this._itemBuyPanel.autoBuyCheck;
                        Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingQualityReq, _currentItem));
                    }
                }
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(26313));
            }
            return;
        }

        protected /* override */ onOptBtn2ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            super.onOptBtn2ClickHandler(arg1);
            if (_currentItem) 
            {
                if (this.optAble(_currentItem)) 
                {
                    _info.qualityAutoBuy = this._itemBuyPanel.autoBuyCheck;
                    this.quickOptAlert.imageItemData = _currentItem;
                    PopupManager.addPopUp(this.quickOptAlert, "window", true);
                    loc1 = this.localToGlobal(new Object /* flash.geom.Point */(_optBtn2.x, _optBtn2.y));
                    this.quickOptAlert.x = loc1.x - this.quickOptAlert.btnOK.x;
                    this.quickOptAlert.y = loc1.y - this.quickOptAlert.btnOK.y;
                }
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(26313));
            }
            return;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            _degreeInfo.text = Language.getString(26323) + "：";
            _degreeInfo.y = _degreeInfo.y + 15;
            _degreeBar.x = _degreeInfo.x + _degreeInfo.textWidth + 2;
            _degreeBar.y = _degreeBar.y + 15;
            _degreeBar.toolTipData = HTMLUtil.addColor(Language.getString(26369), "#ffffff");
            _optBtn1.label = Language.getString(26324);
            _optBtn2.label = Language.getString(26325);
            _optBtn1.x = _bg1.x + _bg2Width / 2 - _optBtn1.width - 20;
            _optBtn1.y = _optBtn1.y + 25;
            _optBtn2.y = _optBtn2.y + 25;
            this._activeBtn = ObjCreate.createGButton(Language.getStringByParam(26428, 0), 22, _optBtn1.y, 86, 24, this, "ButtonRed");
            this._activeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onActiveBtnClickHandler);
            removeChild(_juhunCountBmp);
            _juhunCountBmp.x = _bg1.x + 36;
            _juhunCountBmp.y = _juhunCountBmp.y + 15;
            _juhunCountTxt.htmlText = HTMLUtil.addColor(Language.getString(26326), "#ffff00");
            _juhunCountTxt.x = (_bg2Width - _juhunCountTxt.textWidth) / 2;
            _juhunCountTxt.y = _hLine.y + 15;
            _line.y = _line.y + 30;
            this.initItemBuyPanel();
            return;
        }

        public updateSpiritActiveBtn(): void
        {
            var loc1=Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeWuxingSpritOneKey);
            var loc2=Cache.instance.wuxing.wuxingSpiritInfo.times - Cache.instance.wuxing.wuxingSpiritUseTimes;
            if (loc1) 
            {
                this._activeBtn.visible = true;
                this._activeBtn.label = Language.getStringByParam(26428, loc2);
                _optBtn1.x = 120;
                _optBtn2.x = 208;
                if (_currentItem) 
                {
                    this._activeBtn.toolTipData = Language.getStringByParam(26425, Cache.instance.wuxing.getActiveSpiritCost(_currentItem.wxColor), Cache.instance.wuxing.wuxingSpiritInfo.count);
                }
                else 
                {
                    this._activeBtn.toolTipData = null;
                }
                if (loc2 > 0) 
                {
                    this._activeBtn.enabled = true;
                }
                else 
                {
                    this._activeBtn.enabled = false;
                }
            }
            else 
            {
                _optBtn1.x = 59;
                _optBtn2.x = 172;
                this._activeBtn.visible = false;
            }
            return;
        }

        public shineActiveBtn(): void
        {
            var loc1=Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeWuxingSpritOneKey);
            var loc2=Cache.instance.wuxing.wuxingSpiritInfo.times - Cache.instance.wuxing.wuxingSpiritUseTimes;
            if (loc1 && loc2 > 0) 
            {
                EffectManager.glowFilterReg(this._activeBtn, [FilterConst.guideTipsFilter], 0.6, 10, 5, 5);
            }
            return;
        }

        protected onActiveBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (_currentItem) 
            {
                if (this.optAble(_currentItem)) 
                {
                    TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.ActiveWuXingSpiritOneKeyToday, this.goActiveSpiritBtnOneKey, Language.getStringByParam(26427, Cache.instance.wuxing.getActiveSpiritCost(_currentItem.wxColor), Cache.instance.wuxing.wuxingSpiritInfo.times), null, Alert.OK | Alert.CANCEL);
                }
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(26313));
            }
            return;
        }

        /* internal  */goActiveSpiritBtnOneKey(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingSpiritOneKeyAutoReq, _currentItem));
            return;
        }

        protected /* override */ updateCurrentItem(arg1: ItemData, arg2: Boolean=false): void
        {
            var loc1=0;
            var loc2=0;
            super.updateCurrentItem(arg1, arg2);
            if (arg1) 
            {
                _optItem1.updateData(HTMLUtil.addColor(GameDefConfig.instance.getWuxingTileName(_currentItem.wxColor) + Language.getString(26409), _currentItem.wxColorStr), _currentItem, _currentItem.wxEnergy);
                _optItem2.updateData(HTMLUtil.addColor(GameDefConfig.instance.getWuxingTileName(_nextItem.wxColor) + Language.getString(26409), _nextItem.wxColorStr), _nextItem, _nextItem.wxEnergy);
                this._itemBuyPanel.updateData(arg1);
                loc1 = WuXingConfig.instance.getColorChangeMoneyCost(arg1.wxColor);
                this._itemBuyPanel.updateNeecMoney(loc1);
                loc2 = WuXingConfig.instance.getColorChangeItemCost(arg1.wxColor);
                this._itemBuyPanel.updateNeedCount(loc2);
                this._activeBtn.toolTipData = Language.getStringByParam(26425, Cache.instance.wuxing.getActiveSpiritCost(_currentItem.wxColor), Cache.instance.wuxing.wuxingSpiritInfo.count);
            }
            else 
            {
                this._activeBtn.toolTipData = null;
            }
            return;
        }

        protected /* override */ getNextItem(arg1: ItemData): ItemData
        {
            return WuXingRule.getNextGradeItem(arg1, WuXingRule.GradeQuality);
        }

        protected /* override */ updateProcessBar(arg1: ItemData): void
        {
            var loc1=0;
            super.updateProcessBar(arg1);
            if (arg1) 
            {
                _degreeBar.setValue(arg1.wxLuck, WuXingRule.getLuckTotalValue(arg1));
                if (_lastEffectItem && arg1.uid == _lastEffectItem.uid) 
                {
                    loc1 = arg1.wxEnergy - _lastEffectItem.wxEnergy;
                    if (loc1 > 0) 
                    {
                        _optItem1.onGradeEffect();
                    }
                }
            }
            else 
            {
                _degreeBar.setValue(0, 0);
            }
            return;
        }

        public playValueAddEffect(arg1: int): void
        {
            var loc1=localToGlobal(new Object /* flash.geom.Point */(146, 248));
            var loc2=new ExpAddEffect(new ExpAddEffectInfo(loc1.x, loc1.y, loc1.x, loc1.y, arg1, 1, AttributeTextType.crit));
            loc2.playEffect();
            return;
        }

        protected /* override */ updateMaxGradeItem(arg1: ItemData): void
        {
            super.updateMaxGradeItem(arg1);
            _quickLookItemData = WuXingRule.getNextGradeItem(arg1, WuXingRule.GradeQuality, true);
            _quickLookItem.itemData = _quickLookItemData;
            _quickLookItem.toolTipData = _quickLookItemData.getToolTipData();
            return;
        }

        public /* override */ updatePackData(): void
        {
            super.updatePackData();
            this._itemBuyPanel.updatePackData();
            return;
        }

        public /* override */ updateMoney(): void
        {
            var loc1=0;
            super.updateMoney();
            if (_currentItem) 
            {
                loc1 = WuXingConfig.instance.getColorChangeMoneyCost(_currentItem.wxColor);
            }
            this._itemBuyPanel.updateNeecMoney(loc1);
            return;
        }

        protected /* override */ clear(): void
        {
            super.clear();
            this._itemBuyPanel.clear();
            return;
        }

        protected /* var */_itemBuyPanel: WuXingQualityBuyPanel;

        protected /* var */_quickOptAlert: WuXingQuickGradeUpAlert;

        /* internal */ /* var */_activeBtn: GButton;
    }
